home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Personal Computer World 2009 February
/
PCWFEB09.iso
/
Software
/
Resources
/
Chat & Communication
/
Digsby build 37
/
digsby_setup.exe
/
lib
/
util
/
command_queue.pyo
(
.txt
)
< prev
next >
Wrap
Python Compiled Bytecode
|
2008-10-13
|
5KB
|
192 lines
# Source Generated with Decompyle++
# File: in.pyo (Python 2.5)
from __future__ import with_statement
from util import do, Timer, threaded
from Queue import Queue
from threading import RLock
from functools import wraps
from util import callsback, WorkRequest, ThreadPool, callany
from Queue import Empty
import logging
log = logging.getLogger('cmdq')
class CommandQueue(object):
def __init__(self, start_hooks, end_hooks, shutdown_interval = 30, retry_time = 2):
self.start_hooks = start_hooks
self.end_hooks = end_hooks
self.shutdown_interval = shutdown_interval
self.retry_time = retry_time
self.do_queue = Queue()
self.state_lock = RLock()
self.timer = Timer(shutdown_interval, self.finish)
self.loop_running = False
self.initialized = False
self.initializing = False
self.shutting_down = False
self.timer_valid = False
def add_new(self, .1):
(func, instance, a, k) = .1
self.state_lock.__enter__()
try:
self.timer_valid = False
self.timer.cancel()
self.do_queue.put((func, instance, a, k))
if not self.loop_running:
self.loop_running = True
if self.initialized:
self.flush()
elif not self.initializing:
self.initializing = True
self.initialize()
finally:
pass
def initialize(self):
self.state_lock.__enter__()
try:
if self.shutting_down:
t = Timer(self.retry_time, self.initialize)
t.start()
return None
finally:
pass
try:
do((lambda .0: for f in .0:
f())(self.start_hooks))
except Exception:
self.state_lock
e = self.state_lock
import traceback as traceback
traceback.print_exc()
self.state_lock.__enter__()
try:
self.do_queue = Queue()
self.loop_running = False
self.initialized = False
self.initializing = False
return None
finally:
pass
except:
self.state_lock
self.state_lock.__enter__()
try:
self.initialized = True
self.initializing = False
finally:
pass
self.flush()
initialize = threaded(initialize)
def flush(self):
self.state_lock.acquire()
while True:
self.state_lock.release()
try:
(func, instance, a, k) = self.do_queue.get(False)
except Empty:
break
else:
func(instance, *a, **k)
finally:
self.state_lock.acquire()
self.loop_running = False
self.timer_valid = True
self.timer.start()
self.state_lock.release()
flush = threaded(flush)
def finish(self):
self.state_lock.__enter__()
try:
if not self.timer_valid:
return None
self.initialized = False
self.shutting_down = True
finally:
pass
do((lambda .0: for f in .0:
f())(self.end_hooks))
self.state_lock.__enter__()
try:
self.shutting_down = False
finally:
pass
finish = threaded(finish)
def cmdqueue(qname = 'cmdq'):
def wrapper2(func):
def wrapper1(instance, *args, **kws):
print instance, args, kws
cmdq = getattr(instance, qname)
cmdq.add_new((func, instance, args, kws))
return wrapper1
return wrapper2
def callback_cmdqueue(qname = 'cmdq'):
def wrapper2(func):
def wrapper(instance, callback = (callsback, None), *args, **kws):
requestID = kws.pop('requestID', None)
cmdq = getattr(instance, qname)
def do_thing(*a, **k):
try:
result = func(instance, *args, **kws)
exception = None
except Exception:
e = None
exception = e
result = None
import traceback
import sys as sys
sys.stderr.write('The following exception occurred in callback_cmdqueue:\n')
traceback.print_exc()
if exception:
callany(callback.error, e)
else:
callany(callback.success, result)
cmdq.add_new((do_thing, None, (), { }))
wrapper = None(wraps(func)(wrapper))
return wrapper
return wrapper2